/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pslider.hpp - Slider control class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGSLIDER_
#define _PEGSLIDER_

enum PegSliderBitmaps {
    PBMI_SLIDER_BACKGROUND = 0,
    PBMI_SLIDER_NEEDLE
};


/*--------------------------------------------------------------------------*/
class PegSlideButton : public PegThing
{
    public:
        PegSlideButton(PEGLONG Min, PEGLONG Max, PEGLONG Scale,
                       PEGULONG Flags = 0);
        virtual ~PegSlideButton();

        PEGLONG CheckRange(PEGLONG Val);
        virtual void Draw(const PegRect &Invalid);
        PEGLONG GetCurrentValue(void) {return mCurrent;}
        void KeyMove(PEGINT Direction);
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void ParentShift(PEGINT xShift, PEGINT yShift);

        void Reset(PEGINT Min, PEGINT Max, PEGINT New);
        void SetCurrentValue(PEGLONG iNewVal);
        void SetMaxTravelOffset(PEGINT Max);
        void SetMaxValue(PEGLONG Max);
        void SetMinTravelOffset(PEGINT Min);
        void SetMinValue(PEGLONG Min);
        void SetOffset(PEGINT Offset) { mOffset = Offset; }
        void SetScale(PEGLONG Scale)
        {
            mScale = Scale;
            SetSize();
        }

    protected:
        void CheckSnap(PegPoint DragPos, PEGBOOL Vertical);
        virtual void RecalcCurrentPos(void);
        virtual void SetSize(void);
        virtual void UpdateHorzPos(PEGINT Delta);
        virtual void UpdatePosition(PegPoint Point);
        void UpdateVertPos(PEGINT Delta);

       #ifdef PEG_PRO
        PegGradientStruct mGrad;
       #endif

        PegPoint mBeginDrag;
        PEGLONG  mMin;
        PEGLONG  mMax;
        PEGLONG  mScale;
        PEGLONG  mCurrent;
        PEGINT   mMinPos;
        PEGINT   mMaxPos;
        PEGINT   mSize;
        PEGINT   mOffset;
        PEGBOOL  mDragMode;
        PEGBOOL  mInFlyOver;
};


/*--------------------------------------------------------------------------*/
class PegSlider : public PegThing
{
    public:
        PegSlider(const PegRect &Rect, PEGLONG Min, PEGLONG Max,
                  PEGUINT Id = 0, PEGULONG Style = FF_RAISED,
                  PEGLONG Scale = -1);
        virtual ~PegSlider();

        virtual void Draw(const PegRect &Invalid);

        virtual PEGLONG GetCurrentValue(void)
        {
            CheckSlideButton();
            return mpSlideButton->GetCurrentValue();
        }

        virtual PEGLONG GetMaxValue(void) {return mMax;}
        virtual PEGLONG GetMinValue(void) {return mMin;}
        PEGINT GetNeedleOffset() const { return mNeedleOffset; }
        virtual PEGLONG GetScale(void)    {return mScale;}
        virtual PEGLONG IncrementValue(PEGLONG Val);
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void ParentShift(PEGINT x, PEGINT y);
        virtual void Reset(PEGINT Min, PEGINT Max, PEGINT New);
        virtual void Resize(const PegRect &NewSize);

        virtual void SetCurrentValue(PEGLONG NewVal)
        {
            CheckSlideButton();
            mpSlideButton->SetCurrentValue(NewVal);
        }

        void SetMaxTravelOffset(PEGINT Offset)
        {
            CheckSlideButton();
            mpSlideButton->SetMaxTravelOffset(Offset);
        }
        virtual void SetMaxValue(PEGLONG Max);
        void SetMinTravelOffset(PEGINT Offset)
        {
            CheckSlideButton();
            mpSlideButton->SetMinTravelOffset(Offset);
        }
        virtual void SetMinValue(PEGLONG Min);
        void SetNeedleOffset(PEGINT Offset)
        {
            CheckSlideButton();
            mpSlideButton->SetOffset(Offset);
        }
        virtual void SetScale(PEGINT Scale)
        {
            mScale = Scale;
            CheckSlideButton();
            mpSlideButton->SetScale(Scale);
        }

        virtual void SetStyle(PEGULONG Style);

        PEGINT ValToPos(PEGLONG Val);
        PEGLONG PosToVal(PEGINT Pos);

    protected:
        virtual void CheckSlideButton();

        void DrawBitmapNeedle();
        void DrawScale(void);
        void DrawToComposite();
        virtual void SetTravelPoints();

        PegSlideButton *mpSlideButton;

        PEGLONG mMin;
        PEGLONG mMax;
        PEGLONG mScale;

        PEGINT mMinTravel;
        PEGINT mMaxTravel;
        PEGINT mNeedleOffset;
};



/*--------------------------------------------------------------------------*/
class PegBitmapSlideButton : public PegSlideButton
{
    public:
        PegBitmapSlideButton(PEGLONG Min, PEGLONG Max, PEGLONG Scale,
                       PEGUINT NeedleBmp = 0, PEGULONG Flags = 0);

        virtual void Draw(const PegRect &Invalid);
        PEGUINT GetBitmap() { return mBitmapId; }
        void SetBitmap(PEGUINT BmpId); 

    protected:
        virtual void SetSize(void);

        PEGUINT mBitmapId;

};

/*--------------------------------------------------------------------------*/
class PegBitmapSlider : public PegSlider
{
    public:

        PegBitmapSlider(const PegRect &Rect, PEGLONG Min, PEGLONG Max,
                        PEGUINT BkgndBmp = 0, PEGUINT NeedleBmp = 0,
                        PEGUINT Id = 0, PEGULONG Style = FF_RAISED,
                        PEGLONG Scale = -1);

        virtual void Draw(const PegRect &Invalid);

        PEGUINT GetBitmap(PEGUINT Index) const {
            if (Index)
            {
                return (((PegBitmapSlideButton *) mpSlideButton)->GetBitmap());
            }
            else
            {
                return mBkgBitmap;
            }
        }

        virtual void SetBitmap(PEGINT Index, PEGUINT BmpId)
        {
            if (Index)
            {
                ((PegBitmapSlideButton *)mpSlideButton)->SetBitmap(BmpId);
            }
            else
            {
                mBkgBitmap = BmpId;
            }
        }

    protected:
        void DrawScale(void);
        PEGUINT mBkgBitmap;
        PEGUINT mCompBitmap;

};

#endif

